﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace POS_NEW
{
    public partial class ErrorScreen : Form
    {
        private Timer _timer;
        private int _timerCount = 7;

        public ErrorScreen(string error)
        {
            InitializeComponent();
            _timer = new Timer();
            _timer.Interval = 1000;
            _timer.Tick += new EventHandler(_timer_Tick);
            _timer.Enabled = true;
            this.lbl_Error.Text = error;
        }

        public ErrorScreen(string error, int timeout)
            : this(error)
        {
            _timerCount = timeout;
        }

        public ErrorScreen(string text, string header, int timeout)
            : this(text)
        {
            this.label1.Text = header;
            _timerCount = timeout;
        }

        void _timer_Tick(object sender, EventArgs e)
        {
            _timerCount = _timerCount - 1;
            this.btn_Continue.Text = "Enter - Quay lại (" + _timerCount + ")";
            if (_timerCount < 1)
            {
                btn_Continue_Click(sender, e);
            }
        }

        //protected override void OnPaint(PaintEventArgs e)
        //{
        //    using (Bitmap background = new Bitmap(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName), "Background.gif")))
        //    {
        //        e.Graphics.DrawImage(background, Screen.PrimaryScreen.Bounds, new Rectangle(0, 0, background.Width, background.Height), GraphicsUnit.Pixel);
        //    }
        //}

        private void FormOnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btn_Continue_Click(sender, e);
            }
        }

        private void btn_Continue_Click(object sender, EventArgs e)
        {
            _timer.Enabled = false;
            _timer.Dispose();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}